package com.meicloud.license.filter;

import com.meicloud.license.appl.LicenseMock;
import com.meicloud.license.appl.vo.LicenseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * license验证
 *
 * @author zhanghui145
 * @date 2022/1/10 13:55
 * @since 1.0.0
 */
@Component
public class LicenseFilter implements Filter {

    @Autowired
    LicenseMock licenseMock;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        String code1 = licenseMock.generateRegisterCode();
        System.out.println("拿到了注册码：" + code1);
        String code2 = licenseMock.generateLicenseCode(code1);
        System.out.println("拿到了授权码码：" + code2);
        if (licenseMock.customRegister(code1, code2)) {
            System.out.println("租户注册成功！");
        }
        LicenseDto licenseDto = licenseMock.licenseStatus();
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
    }
}
